/**
 * 格式化时间
 * @param {Date} date
 * @param {string} fmt 
 * @returns 
 */
export const format = (date, fmt) => {

    const _date = new Date(date)

    var o = {
        "M+": _date.getMonth() + 1, //month
        "d+": _date.getDate(), //day
        "D+": _date.getDate(), //day
        "h+": _date.getHours(), //hour
        "HH+": _date.getHours(), //hour
        "m+": _date.getMinutes(), //minute
        "s+": _date.getSeconds(), //second
        "q+": Math.floor((_date.getMonth() + 3) / 3), //季度
        S: _date.getMilliseconds(), //millisecond
    };
    if (/(y+)/.test(fmt) || /(Y+)/.test(fmt))
        fmt = fmt.replace(
            RegExp.$1,
            (_date.getFullYear() + "").substring(4 - RegExp.$1.length)
        );
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(
                RegExp.$1,
                RegExp.$1.length == 1
                    ? o[k]
                    : ("00" + o[k]).substring(("" + o[k]).length)
            );
    return fmt;
};
